package com.lysj.merchant.merchant.repository;

import com.lysj.admin.utils.spring.foundation.base.BaseRepository;
import com.lysj.admin.utils.web.SelectItem;
import com.lysj.merchant.merchant.domain.Store;
import com.lysj.merchant.merchant.vo.StoreUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import javax.xml.ws.RequestWrapper;
import java.util.List;

/**
 * @author Created by wtl on 2019-03-12 17:25:12
 * @description 门店dao
 */
public interface StoreRepository extends BaseRepository<Store> {

    /**
     * 根据门店和用户表查询出商户对应门店包括店长信息
     */
    @Query("select new com.lysj.merchant.merchant.vo.StoreUser(s.id,s.name,s.phone,s.foodType,s.address,u.username,s.createTime) from Store s,User u where s.id = u.storeId and u.userType=2 and s.merchantId=?1")
    List<StoreUser> findStoreInfo(String merchantId);

    /**
     * 根据当前登录店长或者店员id查询门店
     */
    @Query("select new com.lysj.merchant.merchant.vo.StoreUser(s.id,s.name,s.phone,s.foodType,s.address,u.username,s.createTime) from Store s,User u where s.id = u.storeId and u.id=?1")
    Page<StoreUser> findStoreByUserId(String userId, Pageable pageable);


    /**
     * 根据当前登录店长id查询门店信息
     */
    @Query("select new com.lysj.admin.utils.web.SelectItem(s.id,s.name) from Store s,User u where s.id = u.storeId and u.userType in (2,3) and u.id=?1")
    List<SelectItem> findStore(String userId);

    /**
     * 根据当前登录id查询商户的门店列表
     */
    @Query("select new com.lysj.admin.utils.web.SelectItem(s.id,s.name) from Store s,User u where u.merchantId = s.merchantId  and u.userType=1 and u.id=?1")
    List<SelectItem> findMerchantStore(String userId);

    /**
     * 根据商户id查询门店列表
     */
    @Query("select new com.lysj.merchant.merchant.vo.StoreUser(s.id,s.name,s.phone,s.foodType,s.address,s.address,s.createTime) from Store s where s.merchantId=?1")
    Page<StoreUser> findStoreByMerchantId(String merchantId, Pageable pageable);

}